﻿using System;
using System.Collections.Generic;
using System.IO.Compression;
using System.IO;
using System.Text;

namespace CommonHelper
{
    public class ZipHelper
    {
        /// <summary>
        /// 将sourceDirectory压缩成destinationZipFile
        /// </summary>
        /// <param name="sourceDirectory"></param>
        /// <param name="destinationZipFile"></param>
        public static void CreateZip(string sourceDirectory, string destinationZipFile)
        {
            if (Directory.Exists(sourceDirectory))
            {
                // 压缩文件夹到ZIP文件
                ZipFile.CreateFromDirectory(sourceDirectory, destinationZipFile);
            }
        }
        /// <summary>
        /// 解压缩zip
        /// </summary>
        /// <param name="zipFilePath"></param>
        /// <param name="extractPath"></param>
        public static void ExtractZipFile(string zipFilePath, string extractPath)
        {
            // 确保提取路径存在
            Directory.CreateDirectory(extractPath);

            // 使用ZipFile.ExtractToDirectory方法解压缩文件
            ZipFile.ExtractToDirectory(zipFilePath, extractPath);
        }
    }
}
